/**
 * Copyright 2019-2022 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef INCL_HIAI_MODEL_RUNTIME_H
#define INCL_HIAI_MODEL_RUNTIME_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

// NOTE: should be append at tail.
typedef enum {
    HRANI_MODELBUILDER_BUILD,
    HRANI_MODELBUILDER_BUILD_FROM_SHARED_BUFFER,
    // BuiltModel
    HRANI_BUILTMODEL_RESTORE,
    HRANI_BUILTMODEL_RESTORE_FROM_FILE,
    HRANI_BUILTMODEL_SAVE_TO_EXTERNAL_BUFFER,
    HRANI_BUILTMODEL_SAVE,
    HRANI_BUILTMODEL_SAVE_TO_FILE,
    HRANI_BUILTMODEL_CHECK_COMPATIBILITY,
    HRANI_BUILTMODEL_GET_NAME,
    HRANI_BUILTMODEL_SET_NAME,
    HRANI_BUILTMODEL_GET_INPUT_TENSOR_NUM,
    HRANI_BUILTMODEL_GET_INPUT_TENSOR_DESC,
    HRANI_BUILTMODEL_GET_OUTPUT_TENSOR_NUM,
    HRANI_BUILTMODEL_GET_OUTPUT_TENSOR_DESC,
    HRANI_BUILTMODEL_DESTROY,
    // end BuiltModel
    // BuiltModel AIPP
    HRANI_BUILTMODEL_GET_TENSOR_AIPP_INFO,
    HRANI_BUILTMODEL_GET_TENSOR_AIPP_PARA,
    // end BuiltModel AIPP
    // ModelManager
    HRANI_MODELMANAGER_CREATE,
    HRANI_MODELMANAGER_DESTROY,
    HRANI_MODELMANAGER_INIT,
    HRANI_MODELMANAGER_SET_PRIORITY,
    HRANI_MODELMANAGER_RUN,
    HRANI_MODELMANAGER_RUN_ASYNC,
    HRANI_MODELMANAGER_CANCEL,
    HRANI_MODELMANAGER_DEINIT,
    // end ModelManager
    // ModelManager Ext
    HRANI_MODELMANAGER_INIT_WITH_SHARED_MEM_ALLOCATOR,
    // end ModelManager Ext
    // ModelManager AIPP
    HRANI_MODELMANAGER_RUN_AIPP_MODEL_V2,
    // end ModelManager AIPP
    HRANI_MODELBUILDER_BUILDV2,
    HRANI_MODELMANAGER_INITV2,
    HRANI_MODELMANAGER_RUN_V3,
    HRANI_MODELMANAGER_RUN_ASYNC_V3,
    HRANI_MODELMANAGER_RUN_AIPP_MODEL_V3,
    HRANI_BUILTMODEL_RESTORE_FROM_FILE_WITH_SHAPE_INDEX,
    HRANI_SIZE
} HIAI_RUNTIME_API_NAME_INDEX;

typedef enum {
    HIAI_MODELBUILDOPTIONS_CREATE,
    HIAI_MODELBUILDOPTIONS_DESTROY,
    HIAI_MODELBUILDOPTIONS_SETINPUTTENSORDESCS,
    HIAI_MODELBUILDOPTIONS_GETINPUTSIZE,
    HIAI_MODELBUILDOPTIONS_GETINPUTTENSORDESCS,
    HIAI_MODELBUILDOPTIONS_SETFORMATMODEOPTION,
    HIAI_MODELBUILDOPTIONS_GETFORMATMODEOPTION,
    HIAI_MODELBUILDOPTIONS_SETPRECISIONMODEOPTION,
    HIAI_MODELBUILDOPTIONS_GETPRECISIONMODEOPTION,
    HIAI_MODELBUILDOPTIONS_SETDYNAMICSHAPECONFIG,
    HIAI_MODELBUILDOPTIONS_GETDYNAMICSHAPECONFIG,
    HIAI_MODELBUILDOPTIONS_SETMODELDEVICECONFIG,
    HIAI_MODELBUILDOPTIONS_GETMODELDEVICECONFIG,
    HIAI_MODELBUILDOPTIONS_SETTUNINGSTRATEGY,
    HIAI_MODELBUILDOPTIONS_GETTUNINGSTRATEGY,
    HIAI_MODELBUILDOPTIONS_SETESTIMATEOUTPUTSIZE,
    HIAI_MODELBUILDOPTIONS_GETESTIMATEOUTPUTSIZE,
    // dynamicShape
    HIAI_DYNAMICSHAPECONFIG_CREATE,
    HIAI_DYNAMICSHAPECONFIG_SETENABLEMODE,
    HIAI_DYNAMICSHAPECONFIG_GETENABLEMODE,
    HIAI_DYNAMICSHAPECONFIG_SETMAXCACHENUM,
    HIAI_DYNAMICSHAPECONFIG_GETMAXCACHENUM,
    HIAI_DYNAMICSHAPECONFIG_SETCACHEMODE,
    HIAI_DYNAMICSHAPECONFIG_GETCACHEMODE,
    HIAI_DYNAMICSHAPECONFIG_DESTROY,
    // opDeviceOrder
    HIAI_OPDEVICEORDER_CREATE,
    HIAI_OPDEVICEORDER_SETOPNAME,
    HIAI_OPDEVICEORDER_GETOPNAME,
    HIAI_OPDEVICEORDER_SETDEVICEORDER,
    HIAI_OPDEVICEORDER_GETSUPPORTEDDEVICENUM,
    HIAI_OPDEVICEORDER_GetSUPPORTEDDEVICES,
    HIAI_OPDEVICEORDER_DESTROY,
    // cLCustomization
    HIAI_CLCUSTOMIZATION_CREATE,
    HIAI_CLCUSTOMIZATION_SETOPNAME,
    HIAI_CLCUSTOMIZATION_GETOPNAME,
    HIAI_CLCUSTOMIZATION_SETCUSTOMIZATION,
    HIAI_CLCUSTOMIZATION_GETCUSTOMIZATION,
    HIAI_CLCUSTOMIZATION_DESTROY,
    // modelDeviceConfig
    HIAI_MODELDEVICECONFIG_CREATE,
    HIAI_MODELDEVICECONFIG_SETDEVICECONFIGMODE,
    HIAI_MODELDEVICECONFIG_GETDEVICECONFIGMODE,
    HIAI_MODELDEVICECONFIG_SETFALLBACKMODE,
    HIAI_MODELDEVICECONFIG_GETFALLBACKMODE,
    HIAI_MODELDEVICECONFIG_SETMODELDEVICEORDER,
    HIAI_MODELDEVICECONFIG_GETCONFIGMODELNUM,
    HIAI_MODELDEVICECONFIG_GETMODELDEVICEORDER,
    HIAI_MODELDEVICECONFIG_SETOPDEVICEORDER,
    HIAI_MODELDEVICECONFIG_GETCONFIGOPNUM,
    HIAI_MODELDEVICECONFIG_GETOPDEVICEORDER,
    HIAI_MODELDEVICECONFIG_SETDEVICEMEMORYREUSEPLAN,
    HIAI_MODELDEVICECONFIG_GETDEVICEMEMORYREUSEPLAN,
    HIAI_MODELDEVICECONFIG_SETCLCUSTOMIZATION,
    HIAI_MODELDEVICECONFIG_GETCLCUSTOMIZATION,
    HIAI_MODELDEVICECONFIG_DESTROY,
    // quantizeConfig
    HIAI_MODELBUILDOPTIONS_SETQUANTIZECONFIG,
    HIAI_MODELBUILDOPTIONS_GETQUANTIZECONFIGDATA,
    HIAI_MODELBUILDOPTIONS_GETQUANTIZECONFIGSIZE,
    // init
    HIAI_MODELINITOPTIONS_CREATE,
    HIAI_MODELINITOPTIONS_SETPERFMODE,
    HIAI_MODELINITOPTIONS_GETPERFMODE,
    HIAI_MODELINITOPTIONS_SETBUILDOPTIONS,
    HIAI_MODELINITOPTIONS_GETBUILDOPTIONS,
    HIAI_MODELINITOPTIONS_DESTROY,
    // end
    OPTIONS_SIZE,
} HIAI_RUNTIME_OPTIONS_NAME_INDEX;

// NOTE: the order should not be modifiable.
// In ohos system, the HIAI_MODEL_RUNTIME_DIRECT process is temporarily unavailable.
typedef enum HIAI_ModelRuntimeType {
    PLUGIN_MODEL_RUNTIME_HCL,
    HIAI_MODEL_RUNTIME_HCL,
#if !defined(__OHOS__)
    HIAI_MODEL_RUNTIME_DIRECT,
#endif
    FMK_MODEL_RUNTIME_HCL,
    HIAI_MODEL_RUNTIME_BINARY,
    HIAI_MAX_MODEL_RUNTIME_NUM,
} HIAI_ModelRuntimeType;

typedef struct HIAI_SymbolName {
    char* name;
    int32_t index;
} HIAI_SymbolName;

typedef struct HIAI_ModelRuntime {
    void* handle;
    void* symbolList[HRANI_SIZE];
    void* optionsSymbolList[OPTIONS_SIZE];
    HIAI_ModelRuntimeType runtimeType;
} HIAI_ModelRuntime;

HIAI_ModelRuntime* HIAI_ModelRuntime_Load(HIAI_ModelRuntimeType type);
void HIAI_ModelRuntime_UnLoad(HIAI_ModelRuntime* self);

#ifdef __cplusplus
}
#endif

#endif // INCL_HIAI_MODEL_RUNTIME_H